home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Mac / Demo / calldll / testcalldll.py < prev   
Encoding:
Text File  |  2000-06-23  |  3.3 KB  |  133 lines

  1. import calldll
  2. import macfs
  3. import sys
  4. import MacOS
  5. import Res
  6.  
  7. fss, ok = macfs.PromptGetFile("Show me calldll.ppc.slb")
  8.  
  9. lib = calldll.getdiskfragment(fss, 'calldll.ppc.slb')
  10.  
  11. cdll_b_bbbbbbbb = calldll.newcall(lib.cdll_b_bbbbbbbb, 'Byte', 'InByte', 'InByte', 
  12.                 'InByte', 'InByte','InByte', 'InByte','InByte', 'InByte')
  13. cdll_h_hhhhhhhh = calldll.newcall(lib.cdll_h_hhhhhhhh, 'Short', 'InShort', 'InShort', 
  14.                 'InShort', 'InShort','InShort', 'InShort','InShort', 'InShort')
  15. cdll_l_llllllll = calldll.newcall(lib.cdll_l_llllllll, 'Long', 'InLong', 'InLong', 
  16.                 'InLong', 'InLong','InLong', 'InLong','InLong', 'InLong')
  17.                 
  18. cdll_N_ssssssss = calldll.newcall(lib.cdll_N_ssssssss, 'None', 'InString', 'InString',
  19.                 'InString', 'InString', 'InString', 'InString', 'InString', 'InString')
  20.                 
  21. cdll_o_l = calldll.newcall(lib.cdll_o_l, 'OSErr', 'InLong')
  22.  
  23. cdll_N_pp = calldll.newcall(lib.cdll_N_pp, 'None', 'InPstring', 'OutPstring')
  24.  
  25. cdll_N_bb = calldll.newcall(lib.cdll_N_bb, 'None', 'InByte', 'OutByte')
  26. cdll_N_hh = calldll.newcall(lib.cdll_N_hh, 'None', 'InShort', 'OutShort')
  27. cdll_N_ll = calldll.newcall(lib.cdll_N_ll, 'None', 'InLong', 'OutLong')
  28. cdll_N_sH = calldll.newcall(lib.cdll_N_sH, 'None', 'InString', 'InHandle')
  29.  
  30. print 'Test cdll_b_bbbbbbbb'
  31. rv = cdll_b_bbbbbbbb(1, 2, 3, 4, 5, 6, 7, 8)
  32. if rv == 36:
  33.     print 'ok.'
  34. else:
  35.     print 'Failed, returned', rv
  36.     
  37. print 'Test cdll_b_bbbbbbbb negative'
  38. rv = cdll_b_bbbbbbbb(-1, -2, -3, -4, -5, -6, -7, -8)
  39. if rv == -36:
  40.     print 'ok.'
  41. else:
  42.     print 'Failed, returned', rv
  43.  
  44. print 'Test cdll_h_hhhhhhhh'
  45. rv = cdll_h_hhhhhhhh(1, 2, 3, 4, 5, 6, 7, 8)
  46. if rv == 36:
  47.     print 'ok.'
  48. else:
  49.     print 'Failed, returned', rv
  50.     
  51. print 'Test cdll_h_hhhhhhhh negative'
  52. rv = cdll_h_hhhhhhhh(-1, -2, -3, -4, -5, -6, -7, -8)
  53. if rv == -36:
  54.     print 'ok.'
  55. else:
  56.     print 'Failed, returned', rv
  57.  
  58. print 'Test cdll_l_llllllll'
  59. rv = cdll_l_llllllll(1, 2, 3, 4, 5, 6, 7, 8)
  60. if rv == 36:
  61.     print 'ok.'
  62. else:
  63.     print 'Failed, returned', rv
  64.     
  65. print 'Test cdll_l_llllllll negative'
  66. rv = cdll_l_llllllll(-1, -2, -3, -4, -5, -6, -7, -8)
  67. if rv == -36:
  68.     print 'ok.'
  69. else:
  70.     print 'Failed, returned', rv
  71.     
  72. print 'Test cdll_N_ssssssss'
  73. print 'Should print one two three four five six seven eight'
  74. rv = cdll_N_ssssssss('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight')
  75. if rv == None:
  76.     print 'ok.'
  77. else:
  78.     print 'Failed, returned', rv
  79.     
  80. print 'Test cdll_o_l(0)'
  81. rv = cdll_o_l(0)
  82. if rv == None:
  83.     print 'ok.'
  84. else:
  85.     print 'Error, returned', rv
  86.     
  87. print 'Test cdll_o_l(-100)'
  88. try:
  89.     rv = cdll_o_l(-100)
  90.     print 'Error, did not raise exception, returned', rv
  91. except MacOS.Error, arg:
  92.     if arg[0] == -100:
  93.         print 'ok.'
  94.     else:
  95.         print 'Error, returned incorrect exception arg:', arg[0]
  96.     
  97. print 'Test cdll_N_pp'
  98. rv = cdll_N_pp('pascal string')
  99. if rv == 'Was: pascal string':
  100.     print 'ok.'
  101. else:
  102.     print 'Failed, returned', `rv`
  103.     
  104. print 'Test cdll_N_bb'
  105. rv = cdll_N_bb(-100)
  106. if rv == -100:
  107.     print 'ok.'
  108. else:
  109.     print 'Failed, returned', rv
  110.     
  111. print 'Test cdll_N_hh'
  112. rv = cdll_N_hh(-100)
  113. if rv == -100:
  114.     print 'ok.'
  115. else:
  116.     print 'Failed, returned', rv
  117.     
  118. print 'Test cdll_N_ll'
  119. rv = cdll_N_ll(-100)
  120. if rv == -100:
  121.     print 'ok.'
  122. else:
  123.     print 'Failed, returned', rv
  124.  
  125. print 'Test cdll_N_sH'
  126. h = Res.Resource('xyz')
  127. rv = cdll_N_sH('new data', h)
  128. if rv == None and h.data == 'new data':
  129.     print 'ok.'
  130. else:
  131.     print 'Failed, rv is', rv, 'and handle data is', `rv.data`
  132. sys.exit(1)
  133.